/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad de La Frontera
 * License Type: Academic
 */
package orm.tallerdesoa.impl;

import org.orm.*;
import org.hibernate.Query;
import org.hibernate.LockMode;
import java.util.List;
import orm.tallerdesoa.*;

public class Tcp_publicacionDAOImpl implements orm.tallerdesoa.dao.Tcp_publicacionDAO {
	public Tcp_publicacion loadTcp_publicacionByORMID(int pub_id) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_publicacionByORMID(session, pub_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion getTcp_publicacionByORMID(int pub_id) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return getTcp_publicacionByORMID(session, pub_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion loadTcp_publicacionByORMID(int pub_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_publicacionByORMID(session, pub_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion getTcp_publicacionByORMID(int pub_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return getTcp_publicacionByORMID(session, pub_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion loadTcp_publicacionByORMID(PersistentSession session, int pub_id) throws PersistentException {
		try {
			return (Tcp_publicacion) session.load(orm.tallerdesoa.Tcp_publicacion.class, new Integer(pub_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion getTcp_publicacionByORMID(PersistentSession session, int pub_id) throws PersistentException {
		try {
			return (Tcp_publicacion) session.get(orm.tallerdesoa.Tcp_publicacion.class, new Integer(pub_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion loadTcp_publicacionByORMID(PersistentSession session, int pub_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tcp_publicacion) session.load(orm.tallerdesoa.Tcp_publicacion.class, new Integer(pub_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion getTcp_publicacionByORMID(PersistentSession session, int pub_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tcp_publicacion) session.get(orm.tallerdesoa.Tcp_publicacion.class, new Integer(pub_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_publicacion(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return queryTcp_publicacion(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_publicacion(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return queryTcp_publicacion(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion[] listTcp_publicacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return listTcp_publicacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion[] listTcp_publicacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return listTcp_publicacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_publicacion(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_publicacion as Tcp_publicacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public List queryTcp_publicacion(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_publicacion as Tcp_publicacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Tcp_publicacion", lockMode);
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion[] listTcp_publicacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		try {
			List list = queryTcp_publicacion(session, condition, orderBy);
			return (Tcp_publicacion[]) list.toArray(new Tcp_publicacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion[] listTcp_publicacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			List list = queryTcp_publicacion(session, condition, orderBy, lockMode);
			return (Tcp_publicacion[]) list.toArray(new Tcp_publicacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion loadTcp_publicacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_publicacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion loadTcp_publicacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return loadTcp_publicacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion loadTcp_publicacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tcp_publicacion[] tcp_publicacions = listTcp_publicacionByQuery(session, condition, orderBy);
		if (tcp_publicacions != null && tcp_publicacions.length > 0)
			return tcp_publicacions[0];
		else
			return null;
	}
	
	public Tcp_publicacion loadTcp_publicacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tcp_publicacion[] tcp_publicacions = listTcp_publicacionByQuery(session, condition, orderBy, lockMode);
		if (tcp_publicacions != null && tcp_publicacions.length > 0)
			return tcp_publicacions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTcp_publicacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return iterateTcp_publicacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTcp_publicacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession();
			return iterateTcp_publicacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTcp_publicacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_publicacion as Tcp_publicacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTcp_publicacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.tallerdesoa.Tcp_publicacion as Tcp_publicacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("Tcp_publicacion", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion createTcp_publicacion() {
		return new orm.tallerdesoa.Tcp_publicacion();
	}
	
	public boolean save(orm.tallerdesoa.Tcp_publicacion tcp_publicacion) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().saveObject(tcp_publicacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.tallerdesoa.Tcp_publicacion tcp_publicacion) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().deleteObject(tcp_publicacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.tallerdesoa.Tcp_publicacion tcp_publicacion)throws PersistentException {
		try {
			if(tcp_publicacion.getTcp_personaPers() != null) {
				tcp_publicacion.getTcp_personaPers().tcp_publicacion.remove(tcp_publicacion);
			}
			
			return delete(tcp_publicacion);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.tallerdesoa.Tcp_publicacion tcp_publicacion, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(tcp_publicacion.getTcp_personaPers() != null) {
				tcp_publicacion.getTcp_personaPers().tcp_publicacion.remove(tcp_publicacion);
			}
			
			try {
				session.delete(tcp_publicacion);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.tallerdesoa.Tcp_publicacion tcp_publicacion) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession().refresh(tcp_publicacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.tallerdesoa.Tcp_publicacion tcp_publicacion) throws PersistentException {
		try {
			orm.tallerdesoa.TallerdeSOAPersistentManager.instance().getSession().evict(tcp_publicacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tcp_publicacion loadTcp_publicacionByCriteria(Tcp_publicacionCriteria tcp_publicacionCriteria) {
		Tcp_publicacion[] tcp_publicacions = listTcp_publicacionByCriteria(tcp_publicacionCriteria);
		if(tcp_publicacions == null || tcp_publicacions.length == 0) {
			return null;
		}
		return tcp_publicacions[0];
	}
	
	public Tcp_publicacion[] listTcp_publicacionByCriteria(Tcp_publicacionCriteria tcp_publicacionCriteria) {
		return tcp_publicacionCriteria.listTcp_publicacion();
	}
}
